<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script type="text/javascript">
        //直接选择排序
        var foo=[1,3,6,4,5];
        function sort(arr) {
            var maxIndex=arr.length-1;
            var minVal;
            for(let bar=0;bar<=maxIndex;)
            {
                var k;
                for(let i=bar;i<arr.length;i++)
                {
                    if(undefined === minVal)
                    {
                        minVal=arr[i];
                        k=i;
                    }
                    if(arr[i]<minVal)
                    {
                        minVal=arr[i];
                        k=i;
                    }
                }
                var mi= arr[bar];
                arr[bar]=arr[k];
                arr[k]=mi;
                k=undefined;
                minVal=undefined;
                bar++;
            }
            return arr;
        }
        console.log(sort(foo));
    </script>
</body>
</html>